package com.ceres.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

@Service
public class AuthService {

    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 查看cookie中jti是否存在
     * @param request
     * @return
     */
    public String getJtiFromCookie(ServerHttpRequest request){
        //1.获取cookie对象
        MultiValueMap<String, HttpCookie> cookies = request.getCookies();
        HttpCookie cookie = cookies.getFirst("uid");
        if(cookie!=null){
            return cookie.getValue();
        }
        return null;
    }

    /**
     * 查看redis中的token是否过期或者存在
     * @param jti
     * @return
     */
    public String getTokenFromRedis(String jti){
        String token = redisTemplate.boundValueOps(jti).get();
        return token;
    }
}
